| Total Complexity | 2 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 7 | |||
| 8 | @QueryHandler(GetContactByIdQuery) |
||
| 9 | export class GetContactByIdQueryHandler { |
||
| 10 | constructor( |
||
| 11 | @Inject('IContactRepository') |
||
| 12 | private readonly contactRepository: IContactRepository |
||
| 13 | ) {} |
||
| 14 | |||
| 15 | public async execute(query: GetContactByIdQuery): Promise<ContactView> { |
||
| 16 | const contact = await this.contactRepository.findOneById(query.id); |
||
| 17 | |||
| 18 | if (!contact) { |
||
| 19 | throw new ContactNotFoundException(); |
||
| 20 | } |
||
| 21 | |||
| 22 | return new ContactView( |
||
| 23 | contact.getId(), |
||
| 24 | contact.getFirstName(), |
||
| 25 | contact.getLastName(), |
||
| 26 | contact.getCompany(), |
||
| 27 | contact.getEmail(), |
||
| 28 | contact.getPhoneNumber(), |
||
| 29 | contact.getNotes() |
||
| 30 | ); |
||
| 33 |